<!--
  #%L
  thinkbig-ui-operations-manager
  %%
  Copyright (C) 2017 ThinkBig Analytics
  %%
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  #L%
  -->
<card-layout flex header-css="filter-header">
  <header-section>
    <tba-card-filter-header flex layout card-title="vm.cardTitle" page-name="{{vm.pageName}}" view-type="vm.viewType" sort-options="vm.sortOptions"
      on-selected-option="vm.selectedTableOption" filter-model="vm.filter" filter-model-options="{debounce:1000}">
    </tba-card-filter-header>
  </header-section>
  <body-section>
    <md-tabs flex md-selected="vm.tabMetadata.selectedIndex"
             md-align-tabs="top" layout-fill md-dynamic-height>

      <md-tab ng-repeat="tab in vm.tabs"©
              ng-disabled="tab.disabled"
              md-on-select="vm.onTabSelected(tab)" flex
      >
        <md-tab-label> {{tab.title | translate}}</md-tab-label>
        <md-tab-body>
          <md-divider></md-divider>
          <div ng-hide="vm.viewType != 'list'" ng-show="vm.viewType == 'list'">
              <md-progress-linear class="md-accent" md-mode="indeterminate" ng-show="vm.showProgress"></md-progress-linear>
            <md-list flex layout-fill class="list-item-table">
              <md-list-item class="" dir-paginate="feed in tab.data.content |itemsPerPage:vm.paginationData.rowsPerPage" total-items="tab.data.total" current-page="tab.currentPage"
                            pagination-id="tab.title" ng-click="vm.feedDetails($event,feed)" style="height:75px">
                <div layout="row" layout-fill>
                    <div layout="column" class="pad push-top push-left push-right">
                                                          <span ng-class="{'tc-positive':feed.healthText == 'HEALTHY','tc-negative':feed.healthText == 'UNHEALTHY'}">
                                           <ng-md-icon icon="{{feed.icon}}" size="28" hide-xs style="height: inherit">
                                           </ng-md-icon>
                                                          </span>

                    </div>
                  <div layout="column" layout-fill>
                    <div class="item-column md-list-item-text item-column-title" style="margin-bottom:-4px;padding-bottom:0px"
                         layout-fill flex>
                           <span class="item-title-normal" title="{{feed.feed}}">
                              {{feed.displayName === undefined ? feed.feed : feed.displayName.value}}
                            </span>
                    </div>
                    <div layout="row" layout-fill class="pull-top-sm">
                      <div flex="30" layout="column" class="item-column md-list-item-text " ng-if="!feed.stream">
                                    <span ng-class="{'tc-positive':feed.healthText == 'HEALTHY','tc-negative':feed.healthText == 'UNHEALTHY'}">
                                      {{feed.healthText | translate}}
                                    </span>
                        <span class="column-title column-title-bottom pull-top-sm">
                               {{"views.dashboard.feed-health" | translate}}
                                   </span>
                      </div>
                      <div flex="30" layout="column" class="item-column md-list-item-text " ng-if="feed.stream">
                                   <span class="accent-color" ng-if="feed.stream">
                                           <ng-md-icon icon="tune" size="20" hide-xs style="height: inherit">
                                           </ng-md-icon>
                                     STREAM
                                    </span>
                        <span ng-if="feed.stream" class="column-title column-title-bottom  pull-top-sm">{{feed.runningCount | number}} running</span>
                      </div>
                      <div flex="20" layout="column" class="item-column md-list-item-text " >

                                   <span class="item-title-normal {{feed.statusStyle}}">
                                     {{feed.displayStatus | translate}}</span>
                        <span class="column-title column-title-bottom  pull-top-sm">
                                     {{"views.dashboard.status" | translate}}
                                   </span>
                      </div>


                      <div flex="30" layout="column" class="item-column md-list-item-text " ng-if="((!feed.stream  || (feed.stream && !feed.running)))">
                                   <span class="item-title-normal" ng-if="feed.lastStatus != 'UNKNOWN'">
                                      <kylo-timer start-time="feed.timeSinceEndTime" truncated-format="true" add-ago-suffix="true"></kylo-timer>
                                   </span>
                        <span class="item-title-normal" ng-if="feed.lastStatus == 'UNKNOWN'">
                                    --
                                   </span>
                        <span class="column-title column-title-bottom  pull-top-sm">{{"views.dashboard.since" | translate}}</span>
                      </div>
                      <div flex hide-xs layout="column" class="item-column md-list-item-text " ng-if="!feed.stream">
                        <span class="item-title-normal" ng-if="feed.lastStatus != 'UNKNOWN'">{{feed.runTimeString}}</span>
                        <span class="item-title-normal" ng-if="feed.lastStatus == 'UNKNOWN'">--</span>
                        <span class="column-title column-title-bottom  pull-top-sm ">{{"views.dashboard.lastRunTime" | translate}}</span>
                      </div>
                    </div>
                  </div>
                </div>


                <md-divider ng-if="!$last" class="pull-top"></md-divider>
              </md-list-item>
              <md-list-item ng-show="vm.loading == false && vm.total ==0">
                {{"views.dashboard.noResultsFound" | translate}}
              </md-list-item>
              <md-divider></md-divider>
              <md-list-item layout-align="end center" layout-row class="pagination-list-item">
                <dir-pagination-controls pagination-id="tab.title"
                                         auto-hide="false"
                                         max-size="5"
                                         direction-links="true"
                                         boundary-links="false"
                                         template-url="js/common/dir-pagination/dirPagination.tpl.html"
                                         on-page-change="vm.onPaginationChange(newPageNumber)"
                                         label='{{"views.all-page.Rows_per_page" | translate}}'
                                         rows-per-page="vm.paginationData.rowsPerPage"
                                         rows-per-page-options="vm.paginationData.rowsPerPageOptions"
                                         class="pagination-row">
                </dir-pagination-controls>
              </md-list-item>
            </md-list>
          </div>
          <div ng-hide="vm.viewType != 'table'" ng-show="vm.viewType == 'table'">
            <md-table-container>
              <table md-table md-progress="vm.fetchFeedHealthPromise">
                <thead md-head md-order="vm.paginationData.sort" md-on-reorder="vm.onOrderChange">
                <tr md-row>
                  <th md-column name="Feed" md-order-by="feed">{{"views.dashboard.feed" | translate}}</th>
                  <th md-column name="Health" md-order-by="healthText">{{"views.dashboard.feed-health" | translate}}</th>
                  <th md-column name="Status" md-order-by="displayStatus">{{"views.dashboard.status" | translate}}</th>
                  <th md-column name="Since" md-order-by="timeSinceEndTime">{{"views.dashboard.since" | translate}}</th>
                  <th md-column name="Last Run Time" md-order-by="runTime">{{"views.dashboard.lastRunTime" | translate}}</th>
                </tr>
                </thead>
                <tbody md-body>
                <tr md-row
                    ng-repeat="feed in tab.data.content "
                    ng-click="vm.feedDetails($event,feed)">
                  <td md-cell>{{feed.feed}}</td>
                  <td md-cell>
                                    <span ng-class="{'tc-positive':feed.healthText == 'HEALTHY','tc-negative':feed.healthText == 'UNHEALTHY'}">
                                       <ng-md-icon icon="{{feed.icon}}" size="20"
                                                   style="{{job.iconstyle}}">
                                       </ng-md-icon>
                                       <span>{{feed.healthText | translate}}</span></span>

                  </td>
                  <td md-cell>
                                       <span class="{{feed.statusStyle}}">
                                         {{feed.displayStatus | translate}}
                                       </span>
                  </td>
                  <td md-cell>
                    <kylo-timer start-time="feed.timeSinceEndTime" truncated-format="true" add-ago-suffix="true" ng-if="(feed.lastStatus != 'UNKNOWN' && (!feed.stream || (feed.stream && !feed.running)))"></kylo-timer>
                    <span class="item-title-normal" ng-if="feed.lastStatus == 'UNKNOWN'"> -- </span>
                  </td>
                  <td md-cell>
                    <div ng-if="!feed.stream">
                    <span ng-if="feed.lastStatus != 'UNKNOWN'">{{feed.runTimeString}}</span>
                    <span ng-if="feed.lastStatus == 'UNKNOWN'">--</span>
                    </div>
                </tr>
                </tbody>
              </table>
            </md-table-container>

            <md-table-pagination md-limit="vm.paginationData.rowsPerPage" md-page="tab.currentPage" md-total="{{tab.data.total}}" md-on-paginate="vm.onTablePaginationChange"
                                 md-limit-options="[5,10,20,50]"></md-table-pagination>

          </div>


          <div ng-show="vm.loading == true">
            <md-progress-circular md-mode="indeterminate" md-diameter="25px" class="md-accent"></md-progress-circular>
          </div>
        </md-tab-body>
      </md-tab>
    </md-tabs>

  </body-section>
</card-layout>
